package com.hlkj.pay.infrastructure.model.pay;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.framework.mybatis.core.dataobject.BaseDO;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
* 服务商通道映射配置信息
* @TableName t_provider_channel_config
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName("t_provider_channel_config")
public class ProviderChannelConfigDO extends BaseDO {
    /**
    * 服务商编码
    */
    private String providerCode;
    /**
    * 通道编码
    */
    private String channelCode;
    /**
    * 状态 0 关闭 1 启用
     * @see com.hlkj.pay.enums.CommonEnum.YES_NO_TYPE
    */
    private Integer status;
    /**
    * 参数配置
    */
    private String paramsConfig;
    /**
     * 微信公众号id
     */
    private String wechatPubId;
    @TableField(exist = false)
    private List<Long> wechatPubIdList;
    public List<Long> getWechatPubIdList() {
        if(this.wechatPubIdList!=null){
            return this.wechatPubIdList;
        }
        if(StringUtils.hasText(wechatPubId)){
            if (JsonUtils.isJson(wechatPubId)) {
                setWechatPubIdList(JsonUtils.parseArray(wechatPubId, Long.class));
            } else  if (StringUtils.hasText(this.wechatPubId)) {
                List<Long> list = new ArrayList<>();
                list.add(Long.valueOf(wechatPubId));
                setWechatPubIdList(list);
            }
        }
        return this.wechatPubIdList;
    }
    @TableField(exist = false)
    private Long wechatDefaultPubId;
    public Long getWechatDefaultPubId() {
        List<Long> l = getWechatPubIdList();
        if(!CollectionUtils.isEmpty(l)){
            return l.get(0);
        }
        return null;
    }

    /**
     * 微信小程序id
     */
    private String wechatMiniId;
    @TableField(exist = false)
    private List<Long> wechatMiniIdList;
    public List<Long> getWechatMiniIdList() {
        if(this.wechatMiniIdList!=null){
            return this.wechatMiniIdList;
        }
        if (JsonUtils.isJson(wechatMiniId)) {
            setWechatMiniIdList(JsonUtils.parseArray(wechatMiniId, Long.class));
        } else if (StringUtils.hasText(this.wechatMiniId)) {
            List<Long> list = new ArrayList<>();
            list.add(Long.valueOf(wechatMiniId));
            setWechatMiniIdList(list);
        }
        return this.wechatMiniIdList;
    }
    @TableField(exist = false)
    private Long wechatDefaultMiniId;
    public Long getWechatDefaultMiniId() {
        List<Long> l = getWechatMiniIdList();
        if(!CollectionUtils.isEmpty(l)){
            return l.get(0);
        }
        return null;
    }
    /**
     * 支付宝生活号id
     */
    private Long alipayPubId;
    /**
     * 支付宝小程序id
     */
    private Long alipayMiniId;
    
}
